<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryParamsRef" :inline="true" :rules="rules">
      <el-form-item label="商户号"  v-hasPermi="[9]" prop="merchantNoList">
        <el-select class="w-195" multiple v-model="queryParams.merchantNoList" placeholder="请选择" clearable
          style="width: 240px">
          <el-option v-for="item in merchantListData" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="开始时间" prop="startDate">
        <el-date-picker
        v-model="queryParams.startDate"
        type="datetime"
        placeholder="Pick a Date"
        format="YYYY-MM-DD HH:mm"
        time-format="HH:mm"
        value-format="YYYY-MM-DD HH:mm"
      />
      </el-form-item>
      <el-form-item label="结束时间" prop="endDate">
        <el-date-picker
        v-model="queryParams.endDate"
        type="datetime"
        placeholder="Pick a Date"
        format="YYYY-MM-DD HH:mm"
        time-format="HH:mm"
        value-format="YYYY-MM-DD HH:mm"
      />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="searchHandle"
        >搜索
        </el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table  :data="tableData"  border>
      <el-table-column
        label="代收成功金额"
        align="center"
        prop="innerSuccessBalance"
      />
      <el-table-column
        align="center"
        label="代收总额"
        prop="innerTotalBalance"
      />
      <el-table-column
        label="代付成功金额"
        align="center"
        prop="outerSuccessBalance"
      />
      <el-table-column
        align="center"
        label="代付总额"
        prop="outerTotalBalance"
      />
    </el-table>
  </div>
</template>
<script setup>
import {statisticsAll} from "@/api/channel/index.js";
import {  merchantList } from "@/api/deal/index.js";
const { proxy } = getCurrentInstance();
const total = ref(0)

const data = reactive({
  form: {},
  queryParams: {
    merchantNoList: [],
    startDate: '',
    endDate: '',
  },
  rules: {
    startDate: [{type: 'date',required: true, message: "开始时间不能为空", trigger: "change"}],
    endDate: [
      {type: 'date',required: true, message: "结束时间不能为空", trigger: "change"},
    ],
  },
});

const {queryParams, form, rules} = toRefs(data);
const merchantListData = ref([]);
function getMerchantList() {
  merchantList().then((res) => {
    merchantListData.value = res.data.map((item) => {
      return {
        value: item.merchantNo,
        label: item.merchantNo,
      };
    });
  });
}
const tableData = ref([]);
function searchHandle() {
  proxy.$refs["queryParamsRef"].validate((valid, fields) => {
    if (valid) {
  statisticsAll(queryParams.value).then((res) => {
      tableData.value = [res.data];
      total.value = res.total;
  });
    }})
  
}
function resetQuery(){
  proxy.resetForm("queryParamsRef");
  tableData.value = [];
}
onMounted(() => {
  getMerchantList();
})

</script>
